package com.epalmpay.controller.shop.shopuser;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.epalmpay.commom.BaseController;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.system.PageDTO;
import com.epalmpay.dto.shopuser.ShopUserInDTO;
import com.epalmpay.dto.shopuser.ShopUserListOutDTO;
import com.epalmpay.dto.shopuser.ShopUserOutDTO;
import com.epalmpay.dto.shopuser.ShopUserTradeDetailOutDTO;
import com.epalmpay.entity.Page;
import com.epalmpay.entity.ShopUser;
import com.epalmpay.service.member.IMemberGradeService;
import com.epalmpay.service.shop.IShopUserService;
import com.epalmpay.util.Tools;

/** 
 * 说明：门店后台 客户关系管理
 * 创建人：gwn
 * 创建时间：2017-06-01
 */
@Controller
@RequestMapping(value="/shop/shopUser")
public class ShopUserController  extends BaseController{
	
	@Resource
	private IShopUserService shopUserService;
	
	@Resource
	private IMemberGradeService memberGradeService;	

	/**
	 * 显示客户列表
	 * @param shopUserInDTO
	 * @param pageDTO1
	 * @return
	 */
	@RequestMapping(value="/list")
	@ResponseBody
	public ShopUserListOutDTO  list(ShopUserInDTO shopUserInDTO,PageDTO pageDTO){
		ShopUserListOutDTO shopUserListOutDTO=new ShopUserListOutDTO();
		try {
			Page page=Tools.pageEmtity(pageDTO);
			//取得所有会员等级
			shopUserListOutDTO.setMemberGradeList(memberGradeService.getShopGradeList(shopUserInDTO));
			//获取客户列表信息
			List<ShopUserOutDTO> shopUserOutDTOList = shopUserService.getShopUserList(shopUserInDTO,page);			
			shopUserListOutDTO.setShopUserOutDTOList(shopUserOutDTOList);
			shopUserListOutDTO.setPage(page); 
			shopUserListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return shopUserListOutDTO;
		}
		 catch (Exception e) { 
			 shopUserListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return shopUserListOutDTO;
	}	
	
	

	/**
	 * 查看客户列表  根基id  
	 * @param shopUserInDTO
	 * @return
	 */
	@RequestMapping(value="/findShopUserDetailById")
	@ResponseBody
	public ShopUserListOutDTO  findShopUserDetailById(ShopUserInDTO shopUserInDTO){
//		ShopUserOutDTO shopUserOutDTO=new ShopUserOutDTO();
		ShopUserListOutDTO shopUserListOutDTO= new ShopUserListOutDTO();
		ShopUser shopUser=new ShopUser();
		try {   
			shopUser.setId(shopUserInDTO.getId());
			
			ShopUser shopUsers=shopUserService.findShopUserDetailById(shopUser);
			shopUserListOutDTO.setShopUser(shopUsers);
			
			shopUserInDTO.setMemberId(shopUsers.getMemberId());
			List<ShopUserTradeDetailOutDTO> tradeDetailList = shopUserService.queryShopUserDetailList(shopUserInDTO);
			shopUserListOutDTO.setTradeDetailOutDTOList(tradeDetailList);
			if(shopUsers!=null){
//				PropertyCopyUtil.copyPropertiesExclude(shopUsers,shopUserListOutDTO);
				shopUserListOutDTO.setErrorCode(Rescode.SUCCESS, "查询成功");
				return shopUserListOutDTO;
			}else{
				shopUserListOutDTO.setErrorCode("-1", "未查询到记录");
			}
		} catch (Exception e) { 
			shopUserListOutDTO.setErrorCode("-1", "处理出现异常");
			e.printStackTrace();
		}
		return shopUserListOutDTO;
	}
	
	
	
	
	
	
	
	
	
	
	
	

}
